package com.yunhe.spring;

import java.lang.reflect.Method;
import java.util.Arrays;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class AroundLogger implements MethodInterceptor{
	public Object invoke(MethodInvocation arg0)throws Throwable{
		//获取被代理对象
		Object target = arg0.getThis();
		//获取被代理方法
		Method method = arg0.getMethod();
		//获取方法参数
		Object[] args = arg0.getArguments();
		System.out.println("调用"+target+"的"+method.getName()+"方法.方法入参:"+Arrays.toString(args));
		try {
			Object result = arg0.proceed();
			System.out.println("调用"+target+"的"+method.getName()+"方法.方法返回值:"+result);
			return result;
		} catch (Throwable e) {
			System.out.println(method.getName()+"方法发生异常:"+e);
			throw e;
		}
	}
}
